package com.boss.url;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

public class ReadURL {

	public static void main(String[] args) {
		url();
	}

	public static void url() {
		
		Map<String,Integer> map = new HashMap<>();
		
		File file = new File("C:/Users/Lenovo/Desktop/测试url.txt");
		BufferedReader reader = null;
		try {
			//以行为单位读取文件内容，一次读一整行
			reader = new BufferedReader(new FileReader(file));
			
			String tempString = null;
			// 一次读入一行，直到读入null为文件结束
			while ((tempString = reader.readLine()) != null) {
				// 显示行号
				//System.out.println(tempString);
				if(map.containsKey(tempString)){
					map.put(tempString, map.get(tempString) + 1);
				}else{
					map.put(tempString, 1);
				}
			}
			reader.close();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			if (reader != null) {
				try {
					reader.close();
				} catch (IOException e1) {
				}
			}
		}
		
		int max = -1;
		//遍历所有值value,并得到最大的值
		for(int value : map.values()){
			if(value > max){
				max = value;
			}
		}
		
		//获取全部的键
		
		for(Iterator<String> it = map.keySet().iterator();it.hasNext();){
			String key=it.next().toString();   
			Integer i = map.get(key);
			if(i == max){
				System.out.println(key);   
			}		  
		}
	}
}
